package org.example.controller;

import jakarta.annotation.Resource;
import org.example.bean.Book;
import org.example.bean.Category;
import org.example.service.CategoryService;
import org.example.util.JsonResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryCotroller {
    @Resource
    private CategoryService categoryService;
    @GetMapping
    public List<Category> find() {
        return categoryService.list();
    }
    @GetMapping("/page/{page}")
        public JsonResult find(@PathVariable("page") int page){
            return categoryService.findCategory(page);
    }
    @GetMapping("/id/{id}")
    public JsonResult findCategoryById(@PathVariable("id")String id){
        return categoryService.findCategoryById(id);
    }
    @GetMapping("/search/{name}/{page}")
    public JsonResult findCategoryByname(@PathVariable("name")String name,@PathVariable("page") int page){
        return categoryService.findCategoryByname(name,page);
    }

    @PostMapping
    public JsonResult save(Category category){
        return categoryService.saveCategory(category);
    }
        @PutMapping
    private JsonResult update(Category category){
        return categoryService.updateCategory(category);
    }
    @PutMapping("/change_status/{id}/{status}")
    public JsonResult update(@PathVariable("id")String id,@PathVariable("status")int status){
        return categoryService.updateCategoryStatus(id,status);
    }
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id")String id){
        return categoryService.removeCategory(id);
    }
}
